﻿using System;
using System.Data;
using System.Text;
using UDS.Components;

namespace UDS.Entity
{
    /// <summary>
    /// Contains the brief information about a SMS.
    /// </summary>
    public class SMSInfo
    {
        #region properties
        public int ID
        {
            get;
            set;
        }

        public string Sender
        {
            get;
            set;
        }

        public string SenderRealName
        {
            get
            {
                if (!string.IsNullOrEmpty(Sender))
                {
                    return Staff.GetRealNameByUsername(Sender);
                }
                return string.Empty;
            }
        }

        public string Content
        {
            get;
            set;
        }

        /// <summary>
        /// Get or set the date and time when the SMS was sent out.
        /// </summary>
        public DateTime TimeSent
        {
            get;
            set;
        }

        public SMSType Type
        {
            get;
            set;
        }

        /// <summary>
        /// Indicates whether the message has been read by the receiver.
        /// </summary>
        public bool IsNew
        {
            get;
            set;
        }

        public string Receiver
        {
            get;
            set;
        }
        #endregion properties

        internal static SMSInfo ReadSMSFromIDataReader(IDataReader dr)
        {
            SMSInfo sms = new SMSInfo();
            sms.ID = Convert.ToInt32(dr["ID"]);
            sms.Sender = Convert.ToString(dr["Sender"]);
            sms.Receiver = Convert.ToString(dr["Receiver"]);
            sms.Content = Convert.ToString(dr["Content"]);
            sms.Type = (SMSType)Convert.ToInt32(dr["Type"]);
            sms.IsNew = !Convert.ToBoolean(dr["IsRead"]);
            sms.TimeSent = Convert.ToDateTime(dr["SendTime"]);
            return sms;
        }
    }
}
